package com.richman.controller;

import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Vector;

import org.json.JSONObject;

import com.richman.hg.HGManager;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.SendData;
import com.richman.utils.Common;
import com.richman.utils.SoundThread;

public class SpecialAutoBetCentralManager {
	private String bettype = "";
	private String updown = "";
	
	
	
	
	public int dobetgameps38(String bettypearg, String updownarg, Event event, int betgold, double specialMinRatio) {
		try {
			SimpleDateFormat dfSec = new SimpleDateFormat("HH:mm:ss");
			if(event == null) {
				System.out.println(dfSec.format(System.currentTimeMillis()) + ":event为空,投注失败");
				return 0;
			}
			
			//Common.logOut("开始投注PS38新大小");
			
			
			bettype = bettypearg;
			updown = updownarg;

			Event betgame = event;
			
			
			String hgTeamlbStr = "";
			String ps38Teamlbstr = "";
			
			
			String ps38typedetail = "";
			
			String ps38betid = "";
			
			String wtypestr = "";
			
			String typestr = "";
			

			
			String strongstr = "";
			
			String ps38betpankou = "";
			
			String gidstr = "";
			
			
			{
				
				gidstr = Long.toString(event.eventId);//betgame.hgevent.gid;
				
				if(bettype.contains("大小")) {
					ps38betid = event.wholeDXPBetID;
				}else {
					ps38betid = event.wholeRQPBetID;
				}
				
			}
			
			
			//滚球大小
			if(bettype.contains("滚球") && bettype.contains("大小")) {
				wtypestr += "R";
			}
			

			
			if(bettype.contains("让球")) {
				
				wtypestr += "R";
				
				if(updown.contains("1")) {
					//hgTeamlbStr = "皇冠:" + betgame.hgevent.homeTeam + "@";
					ps38Teamlbstr = event.homeTeam + "@";
					ps38typedetail = "主";
					

					
				}else {

					ps38Teamlbstr = event.awayTeam + "@";
					ps38typedetail = "客";

				}
				
				
				
				
				if(bettype.contains("全场")) {
					ps38betpankou = event.wholerqppankou;
					
				}else {
					ps38betpankou = event.halfrqppankou;					
				}
				

				
			}else {
				
				wtypestr += "OU";
				
				if(updown.contains("1")) {
					hgTeamlbStr = "皇冠:" +  "大@";
					ps38Teamlbstr = "小@";
					ps38typedetail = "小";
					
					typestr = "C";


				}else {
					hgTeamlbStr = "皇冠:" + "小@";
					ps38Teamlbstr = "大@";
					ps38typedetail = "大";
					
					typestr = "H";

				}
				
				
				if(bettype.contains("全场")) {
					ps38betpankou = event.wholeDXPPankou;
				}else {
					ps38betpankou = event.halfDXPPankou;
				}
				
				
			}
			

			//滚球让球
			if(bettype.contains("滚球") && bettype.contains("让球")) {
				wtypestr += "E";
			}
			
			
			
			Map<String, String> ps38oddUpdres = BetClient.betCtrMng.updatePS38Ratio(ps38betid, Long.toString(event.eventId), bettype, ps38typedetail, ps38betpankou);
			

			
			
			if(ps38oddUpdres == null) {
				
				System.out.println(dfSec.format(System.currentTimeMillis()) + ":获取赔率失败");
				
				return 0;
			}
			
			Double ps38ratio = Double.parseDouble(ps38oddUpdres.get("ratio"));
			double compareps38ratio = ps38ratio;
			if(ps38ratio<0) {
				compareps38ratio = 2.0+ ps38ratio;
			}
			
			if(compareps38ratio < specialMinRatio) {
				Common.logOut("赔率不符:" + compareps38ratio);
				return 0;
			}

			Double ps38pankou = Double.parseDouble(ps38oddUpdres.get("pankou"));
			

			
			double ps38betgold = betgold + 0.0;//DaShuiClient.mainWnd.gethgBetAmount() * DaShuiClient.mainWnd.getps38betRatio();
			
//			if(Double.parseDouble(ps38oddUpdres.get("maxbet"))   < BetClient.mainWnd.getstartBetGold() ){
//				Common.logOut("平博最大投注值小于起投标准");
//				return;
//			}
			
			

			
			
			

			
			if(ps38betgold < Double.parseDouble(ps38oddUpdres.get("minbet"))) {
				ps38betgold = Double.parseDouble(ps38oddUpdres.get("minbet")) + 1.0;
			}
			
			
			
			
			
			
			

			
			
			String betres = "";

			
			BetAdyData bad = new BetAdyData();
			
			
			
			bad.hgps38 = updownarg;
			
			bad.currenttime = dfSec.format(System.currentTimeMillis());
			
			bad.league = event.leagueName;
			bad.teams = event.homeTeam + "-vs-" + event.awayTeam;
			bad.time = event.duringTime;
			
			
			bad.score = event.homeTeamScore + ":" + event.awayTeamScore;
			
			bad.hgeventid = Long.toString(event.eventId);
			
			bad.bettype = bettype;
			
			//bad.hgbettype = hgTeamlbStr.replace("皇冠:", "") + oddUpdres.get("ratio");
			
			
			bad.betpankou = ps38betpankou;
			bad.hgbettime = Long.toString(System.currentTimeMillis());
			
			bad.hgbetres = "";
			
			bad.ticketid = "";
			bad.gid = gidstr;

			

			
			double ps38ratio1 = ps38ratio;
			if(ps38ratio< 0) {
				ps38ratio1 = 2.0 + ps38ratio1;
			}
			


			
			bad.ps38eventid = Long.toString(event.eventId);
			
			

			
			bad.ps38rebetflag = BetClient.betCtrMng.getPS38BetAccount();
			

			
			int ps38minbetgold = (int)Double.parseDouble(ps38oddUpdres.get("minbet"));
			int ps38maxbetgold = (int)Double.parseDouble(ps38oddUpdres.get("maxbet"));
			
			if(ps38betgold > ps38maxbetgold) {
				
				ps38betgold = ps38maxbetgold;
			}
			
			
			
			//sleep
			
//			int refreshdelaybettime = BetClient.mainWnd.getrefreshdelaybettime();
//			
//			if(refreshdelaybettime > 0 ) {
//				Thread.sleep(refreshdelaybettime * 1000);
//			}
			
			

			//bet ps38
			Map<String, String> rval = BetClient.betCtrMng.ps38dobet(ps38oddUpdres, (int)ps38betgold);
			

					

					
					bad.bettype = bettype;
					

					bad.hgbettime = bad.hgbettime = Long.toString(System.currentTimeMillis());

					bad.gid = gidstr;



					
					
//					if(rval.containsKey("rebet")) {
//						bad.ps38rebetflag = "1";
//					}else {
//						bad.ps38rebetflag = "0";
//					}
					
					
					if(rval.get("status").equals("1")) {
						bad.wagerId = rval.get("wagerId");
						bad.hgbetres = "1";
						//bad.ps38bettime = rval.get("bettime");
						bad.hgbettype   = ps38Teamlbstr + rval.get("ratio");
						bad.hgbetgold = Integer.toString((int)ps38betgold);
						BetClient.betCtrMng.updateSpecialBetLogData(bad);
						BetClient.betCtrMng.updateSpecialBetAdyData(bad);
						return (int)ps38betgold;						
					}else if(rval.get("status").equals("0")){						
						bad.wagerId = rval.get("wagerId");
						bad.hgbetres = "0";
						//bad.ps38bettime = rval.get("bettime");
						bad.hgbettype = ps38Teamlbstr + rval.get("ratio");
						bad.hgbetgold = Integer.toString((int)ps38betgold);
						BetClient.betCtrMng.updateSpecialBetLogData(bad);
						BetClient.betCtrMng.updateSpecialBetAdyData(bad);
						return (int)ps38betgold;
					}else {
						bad.hgbetres = "-2";
						BetClient.betCtrMng.updateSpecialBetLogData(bad);
						return 0;
					}

		}catch(Exception e) {
			
			e.printStackTrace();
			return 0;
			
		}

	}
	
	
	public int dobetgameisn(String bettypearg, String updownarg, HGEvent hgevent, int betgold, double specialMinRatio, Vector<Double> hgpankous) {
		
		try {

			bettype = bettypearg;
			updown = updownarg;



			SimpleDateFormat dfSec = new SimpleDateFormat("HH:mm:ss");
			
			SimpleDateFormat dfDebug = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


			String betres = "";

			
			
			BetAdyData bad = new BetAdyData();
			
			if(bettype.contains("大小")) {
				if(updownarg == "1") {
					bad.hgbettype = "大";
				}else {
					bad.hgbettype = "小";
				}
			}else {
				if(updownarg == "1") {
					bad.hgbettype = hgevent.homeTeam;
				}else {
					bad.hgbettype = hgevent.awayTeam;
				}
			}
			
			
			
			bad.hgps38 = updownarg;
			
			bad.currenttime = dfSec.format(System.currentTimeMillis());
			
			bad.league = hgevent.leagueName;
			bad.teams = hgevent.homeTeam + "-vs-" + hgevent.awayTeam;
			bad.time = hgevent.eventTime;
			
			bad.betpankou = "";
			
			
			
			bad.score = hgevent.homeTeamScore + ":" + hgevent.awayTeamScore;
			
			bad.hgeventid = hgevent.eventId;
			
			bad.bettype = bettype;
			
			bad.ps38rebetflag = BetClient.betCtrMng.getISNBetAccount();
			
			bad.hgbettime = Long.toString(System.currentTimeMillis());
			
			bad.hgbetres = "";
			
			bad.ticketid = "";

			String currentTime = dfDebug.format(System.currentTimeMillis());
			

			String hgHometeam = hgevent.homeTeam;
			String hgAwayteam = hgevent.awayTeam;
			
			String isnHometeam = "";
			String isnAwayteam = "";
			
			System.out.println("isn开始投注----------------------------------------------");
			
			System.out.println("isn投注时间: " + currentTime);
			
			System.out.println("isn投注 皇冠球队: " + hgHometeam + "-vs-" + hgAwayteam);
			
			try {
				BetClient.isnteamsLock.readLock().lock();
				
				for(String[] team: BetClient.isnteams) {

					if(isnHometeam.equals("") && team[0].equals(hgHometeam)) {
						isnHometeam = team[1];
					}
					
					if(isnAwayteam.equals("") && team[0].equals(hgAwayteam)) {
						isnAwayteam = team[1];
					}
					
					if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
						break;
					}
				}
				
				BetClient.isnteamsLock.readLock().unlock();
				
			}catch(Exception e) {
				BetClient.isnteamsLock.readLock().unlock();
				e.printStackTrace();
			}
			
			if(isnHometeam.equals("")||isnAwayteam.equals("")) {
				System.out.println("isn球队未匹配 返回");
				return 0;
			}

			System.out.println("isn投注 isn球队: " + isnHometeam + "-vs-" + isnAwayteam);
			
			System.out.println("投注最低水位: " + Double.toString(specialMinRatio));

			if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
				String res = BetClient.betCtrMng.isndobet(isnHometeam, isnAwayteam, updownarg, specialMinRatio, betgold, hgpankous);
				
				if(res != null) {

					
					JSONObject jb = new JSONObject(res);
					if(jb.getBoolean("success") == true) {
						
						bad.gid = Long.toString(jb.getLong("betId"));
						bad.betpankou = jb.getString("pankou");
						bad.hgbettype = jb.getString("betTeam") + "@" + jb.getString("odds");
						bad.score = jb.getString("score");
						bad.hgbetgold = Integer.toString(jb.getInt("stake"));
						String message = jb.getString("responseMessage");
						if(message.contains("等待")) {
							bad.hgbetres = "0";
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
							BetClient.betCtrMng.updateSpecialBetAdyData(bad);
							return jb.getInt("stake");
						}else if(message.contains("成功")) {
							bad.hgbetres = "1";
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
							BetClient.betCtrMng.updateSpecialBetAdyData(bad);
							return jb.getInt("stake");
						}else if(message.contains("失败")) {
							bad.hgbetres = "-2";
							bad.ps38betres = message;
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}else{
							bad.hgbetres = message;
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}

					}else {
						bad.hgbetres = jb.getString("responseMessage");
						if(!bad.hgbetres.contains("红牌")) {
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}else if(bad.hgbetres.contains("PS38RATIO")) {
							return -10;
						}else {
							return -1;
						}
						
					}

				}else {
					return 0;
				}
				
			}
			
			
			return 0;


			
		}catch(Exception e) {
			
			e.printStackTrace();
			return 0;
			
		}
	}
	
	
	
	
	public int dobetgameisndxq(String bettypearg, String updownarg, HGEvent hgevent, int betgold, double newBigMinRatio, Vector<Double> hgpankous) {
		
		try {

			bettype = bettypearg;
			updown = updownarg;



			SimpleDateFormat dfSec = new SimpleDateFormat("HH:mm:ss");
			
			SimpleDateFormat dfDebug = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


			String betres = "";

			
			
			BetAdyData bad = new BetAdyData();
			
			if(bettype.contains("大小")) {
				if(updownarg == "1") {
					bad.hgbettype = "大";
				}else {
					bad.hgbettype = "小";
				}
			}
			
			
			
			bad.hgps38 = updownarg;
			
			bad.currenttime = dfSec.format(System.currentTimeMillis());
			
			bad.league = hgevent.leagueName;
			bad.teams = hgevent.homeTeam + "-vs-" + hgevent.awayTeam;
			bad.time = hgevent.eventTime;
			
			
			bad.betpankou = "";
			
			
			
			bad.score = hgevent.homeTeamScore + ":" + hgevent.awayTeamScore;
			
			bad.hgeventid = hgevent.eventId;
			
			bad.bettype = bettype;
			
			bad.ps38rebetflag = BetClient.betCtrMng.getISNBetAccount();
			
			bad.hgbettime = Long.toString(System.currentTimeMillis());
			
			bad.hgbetres = "";
			
			bad.ticketid = "";

			String currentTime = dfDebug.format(System.currentTimeMillis());
			

			String hgHometeam = hgevent.homeTeam;
			String hgAwayteam = hgevent.awayTeam;
			
			String isnHometeam = "";
			String isnAwayteam = "";
			
			System.out.println("isn开始投注大小球----------------------------------------------");
			
			System.out.println("isn投注时间: " + currentTime);
			
			System.out.println("isn投注 皇冠球队: " + hgHometeam + "-vs-" + hgAwayteam);
			
			try {
				BetClient.isnteamsLock.readLock().lock();
				
				for(String[] team: BetClient.isnteams) {

					if(isnHometeam.equals("") && team[0].equals(hgHometeam)) {
						isnHometeam = team[1];
					}
					
					if(isnAwayteam.equals("") && team[0].equals(hgAwayteam)) {
						isnAwayteam = team[1];
					}
					
					if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
						break;
					}
				}
				
				BetClient.isnteamsLock.readLock().unlock();
				
			}catch(Exception e) {
				BetClient.isnteamsLock.readLock().unlock();
				e.printStackTrace();
			}
			
			if(isnHometeam.equals("")||isnAwayteam.equals("")) {
				System.out.println("isn球队未匹配 返回");
				return 0;
			}

			System.out.println("isn投注 isn球队: " + isnHometeam + "-vs-" + isnAwayteam);
			
			System.out.println("投注水位: " + Double.toString(newBigMinRatio));

			if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
				String res = BetClient.betCtrMng.isndobetdxq(isnHometeam, isnAwayteam, "1", newBigMinRatio, betgold, hgpankous);
				
				if(res != null) {

					
					JSONObject jb = new JSONObject(res);
					if(jb.getBoolean("success") == true) {
						
						bad.gid = Long.toString(jb.getLong("betId"));
						bad.betpankou = jb.getString("pankou");
						bad.hgbettype = jb.getString("betTeam") + "@" + jb.getString("odds");
						bad.score = jb.getString("score");
						bad.hgbetgold = Integer.toString(jb.getInt("stake"));
						String message = jb.getString("responseMessage");
						if(message.contains("等待")) {
							bad.hgbetres = "0";
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
							BetClient.betCtrMng.updateSpecialBetAdyData(bad);
							return jb.getInt("stake");
						}else if(message.contains("成功")) {
							bad.hgbetres = "1";
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
							BetClient.betCtrMng.updateSpecialBetAdyData(bad);
							return jb.getInt("stake");
						}else if(message.contains("失败")) {
							bad.hgbetres = "-2";
							bad.ps38betres = message;
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}else{
							bad.hgbetres = message;
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}

					}else {
						bad.hgbetres = jb.getString("responseMessage");
						if(!bad.hgbetres.contains("红牌")) {
							BetClient.betCtrMng.updateSpecialBetLogData(bad);
						}else if(bad.hgbetres.contains("PS38RATIO")) {
							return -10;
						}else {
							return -1;
						}
						
					}

				}else {
					return 0;
				}
				
			}
			
			
			return 0;


			
		}catch(Exception e) {
			
			e.printStackTrace();
			return 0;
			
		}
	}
	
	
	
	
	public int dobetgame(String bettypearg, String updownarg, HGEvent hgevent, int betgold, double specialMinRatio) {
		try {

			bettype = bettypearg;
			updown = updownarg;

			String wtypestr = "";
			
			String typestr = "";
			
			String gnumstr = "";
			
			String strongstr = "";
			
			String gidstr = "";
			
			
			if(bettype.contains("半场")) {
				wtypestr = "H";	
				
				gidstr = hgevent.hgid;
				
			}else {
				
				gidstr = hgevent.gid;
				
				
			}
			
			
			//滚球大小
			if(bettype.contains("滚球") && bettype.contains("大小")) {
				wtypestr += "R";
			}
			

			
			if(bettype.contains("让球")) {
				
				wtypestr += "R";
				
				if(updown.contains("1")) {

					typestr = "H";
					gnumstr = hgevent.gnumh;
					
				}else {
					
					
					typestr = "C";
					gnumstr = hgevent.gnumc;
				}
				
				
				
				
				if(bettype.contains("全场")) {
					
					strongstr = hgevent.strong;
				}else {
					
					strongstr = hgevent.hstrong;
				}
				

				
			}else {
				
				wtypestr += "OU";
				
				if(updown.contains("1")) {
					
					
					typestr = "C";
					gnumstr = hgevent.gnumc;

				}else {
					
					
					typestr = "H";
					gnumstr = hgevent.gnumh;
				}
				
			}
			

			//滚球让球
			if(bettype.contains("滚球") && bettype.contains("让球")) {
				wtypestr += "E";
			}
		
//			double specialMinRatio = DaShuiClient.mainWnd.getSpecialMinRatio();
//			
//			double specialDXQMinRatio = DaShuiClient.mainWnd.getSpecialDXQMinRatio();
			
			//增加是否判断红盘
			
			if(BetClient.mainWnd.getIgnoreRedcard()==false) {
				for(int i = 0; i < HGManager.redcardsRecords.size(); i++) {
					if(HGManager.redcardsRecords.elementAt(i).gnumh.equals(gnumstr)) {
						if(Integer.parseInt(HGManager.redcardsRecords.elementAt(i).redcardh) > 0) {
							System.out.println(hgevent.homeTeam + "有红牌，不投注");
							return 0;
						}
					}
					
					if(HGManager.redcardsRecords.elementAt(i).gnumc.equals(gnumstr)) {
						if(Integer.parseInt(HGManager.redcardsRecords.elementAt(i).redcardc) > 0) {
							System.out.println(hgevent.awayTeam + "有红牌，不投注");
							return 0;
						}
					}
				}
			}
			

			
			Map<String, String> oddUpdres = BetClient.betCtrMng.updateSpecialAccountRatio(gidstr, typestr, gnumstr, strongstr, wtypestr + typestr, wtypestr);
			

			Double hgratio = Double.parseDouble(oddUpdres.get("ratio"));
			
			
			
			Double hgpankou = Double.parseDouble(oddUpdres.get("pankou"));
			

			
			int hgmaxbetgold = Integer.parseInt(oddUpdres.get("maxbet").replace(",", ""));
			
			//hgmaxbetgold = 600;
			
			//int hgsetbetgold = DaShuiClient.mainWnd.gethgBetAmount();
			
			
			
			
			
			int hgbetgold = betgold;
			if(hgmaxbetgold < hgbetgold) {
				hgbetgold = hgmaxbetgold;
			}
			

			SimpleDateFormat dfSec = new SimpleDateFormat("HH:mm:ss");
			
			if(oddUpdres == null ) {
				
				System.out.println(dfSec.format(System.currentTimeMillis()) + ":获取赔率失败");
				
				return 0;
			}
			
			
			String betres = "";

			
			BetAdyData bad = new BetAdyData();
			
			if(bettype.contains("大小")) {
				if(updownarg == "1") {
					bad.hgbettype = "大" + oddUpdres.get("ratio");
				}else {
					bad.hgbettype = "小" + oddUpdres.get("ratio");
				}
			}else {
				if(updownarg == "1") {
					bad.hgbettype = hgevent.homeTeam + oddUpdres.get("ratio");
				}else {
					bad.hgbettype = hgevent.awayTeam + oddUpdres.get("ratio");
				}
			}
			
			
			
			bad.hgps38 = updownarg;
			
			bad.currenttime = dfSec.format(System.currentTimeMillis());
			
			bad.league = hgevent.leagueName;
			bad.teams = hgevent.homeTeam + "-vs-" + hgevent.awayTeam;
			bad.time = hgevent.eventTime;
			
			bad.betpankou = oddUpdres.get("pankou");
			
			
			
			bad.score = hgevent.homeTeamScore + ":" + hgevent.awayTeamScore;
			
			bad.hgeventid = hgevent.eventId;
			
			bad.bettype = bettype;
			
			
			
			bad.hgbettime = Long.toString(System.currentTimeMillis());
			
			bad.hgbetres = "";
			
			bad.ticketid = "";
			bad.gid = gidstr;
			bad.hgbetgold = Integer.toString(hgbetgold);
			bad.ps38rebetflag = BetClient.betCtrMng.getHGBetAccount();
			
			double hgratio1 = hgratio;
			if(hgratio < 0) {
				hgratio1 = 2.0 + hgratio;
			}
			
			if(hgratio1 < specialMinRatio) {
				System.out.println(hgevent.homeTeam + ":投注水位低于最低水位," + Double.toString(hgratio1));
				bad.hgbetres = "赔率不符条件";
				BetClient.betCtrMng.updateSpecialBetLogData(bad);
				return 0;
			}


			bad.wagerId = "";
			bad.ps38betres = "";
			//bad.ps38bettime = dfSec.format(System.currentTimeMillis());
			
			//bad.ps38rebetflag = "0";

		
			//int hgminbetgold = Integer.parseInt(oddUpdres.get("minbet"));
			int hgminbetgold = Integer.parseInt(oddUpdres.get("minbet").replace(",", ""));
			//int hgmaxbetgold = Integer.parseInt(oddUpdres.get("maxbet").replace(",",""));
			
			
			if(hgbetgold < hgminbetgold || hgbetgold > hgmaxbetgold) {
				System.out.println("金额不对");
				return 0;
			}
			
			
		
			

			Map<String,String> res = BetClient.betCtrMng.hgdospecialbet(oddUpdres.get("betParam"), hgbetgold);
			

			if(res == null) {
				System.out.println("auto bet: 皇冠账号尚未登录");
				
				System.out.println(dfSec.format(System.currentTimeMillis())  + ": 皇冠账号尚未登录,投注返回null:" + bad.toString());
				bad.hgbetres = "账号掉线";
				BetClient.betCtrMng.updateSpecialBetAdyData(bad);
				
				return 0;
				
				//messagelb.setForeground(new Color(255,0,0));
			}else {
				
				if(res.get("status").equals("1") || res.get("status").equals("0")) {
					

					
					bad.league = hgevent.leagueName;
					bad.teams = hgevent.homeTeam + "-vs-" + hgevent.awayTeam;
					bad.time = hgevent.eventTime;
					
					
					
					
					bad.hgeventid = hgevent.eventId;
					
					bad.bettype = bettype;
					
					bad.hgbettype = res.get("betteam") + "@ " + res.get("betratio");
					bad.betpankou = res.get("betpankou");
					bad.hgbettime = bad.hgbettime = Long.toString(System.currentTimeMillis());
					
					bad.hgbetres = res.get("status");
					
					bad.ticketid = res.get("ticketid");
					bad.gid = gidstr;
					bad.hgbetgold = Integer.toString(hgbetgold);
					
					
					
					
					
					double bethgratio = Double.parseDouble(res.get("betratio"));
					if(bethgratio < 0) {
						bethgratio = 2.0 + bethgratio;
					}
					
					BetClient.betCtrMng.updateSpecialBetLogData(bad);
					BetClient.betCtrMng.updateSpecialBetAdyData(bad);
					//todo remove 测试切换账号投注
					if(res.get("status").equals("1")) {
						//BetClient.betCtrMng.useNextAccount();
					}
					
					BetClient.divider = 1; //投注成功，恢复
					return hgbetgold;
					

					}else {
						
						if(res.get("status").equals("-4") ) {
							//使用下一个特殊账号
							BetClient.divider = BetClient.divider*2;//股东受限
							BetClient.betCtrMng.useNextAccount();
						}
						
						if(res.get("status").equals("-1")) {
							BetClient.betCtrMng.useNextAccount();
						}
						
						bad.hgbetres = res.get("status");
						BetClient.betCtrMng.updateSpecialBetLogData(bad);
						
						return 0;
						//投注失败
						
					}

				}
				

			
		}catch(Exception e) {
			
			e.printStackTrace();
			return 0;
			
		}
	}
}
